package com.zf.zffencheng.strategy;

import com.zf.zffencheng.exception.ResultException;
import lombok.extern.log4j.Log4j2;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ClassName: HardwarePartnerFactory <br/>
 * Description:  <br/>
 * date: 2021/5/31 9:58<br/>
 *
 * @author william <br/>
 */
@Log4j2
public class HardwarePartnerFactory {
    public static final Map<Integer, HardwarePartnerStrategy> HARDWARE_PARTNER_STRATEGY_MAP = new ConcurrentHashMap<>();
    public static void register(Integer key, HardwarePartnerStrategy service) {
        log.info("设备加载:key:{}, class:{}", key, service.getClass().getName());
        HARDWARE_PARTNER_STRATEGY_MAP.put(key, service);
    }

    public static HardwarePartnerStrategy get(Integer key) {
        HardwarePartnerStrategy service = HARDWARE_PARTNER_STRATEGY_MAP.get(key);
        if (service == null) {
            throw new ResultException(511, "设备类型不对");
        }
        return service;
    }


}
